 // index.js
// 获取应用实例
var that,
  app = getApp(),
  api = new (require('../../utils/api.js')),
  util = new (require('../../utils/util.js')),
  headimg = api.getimgurl();
Page({
  data: {
    headimg,
    viewcount:222,
    fabucount:20,
    usercount:10,
    btnlist: [
      {
        code:'sbzl',
        name: '设备租赁',
        pic: 'btn_sbzl'
      },
      {
        code:'qz',
        name: '求职',
        pic: 'qiuzhi'
      },
      {
        code:'fwzs',
        name: '房屋租售',
        pic: 'fwzl'
      },
      {
        code:'esjy',
        name: '二手交易',
        pic: 'esjy'
      },
    ],
    activeIdx: 0,
    carouselimg: [],
    noticelist: ['今日招工统计信息320条', '夏日嗨翻天，建筑港积分送不停'],
    employmentList: [
      {
        title: '广东省东莞市-招瓦工班',
        num: 6,
        price: '面议',
        detail: '工地生活区厨房厕所冲凉房水沟，砌筑抹灰，贴墙地砖，包工面议'
      },
      {
        title: '广东省东莞市-招瓦工班',
        num: 6,
        price: '面议',
        detail: '工地生活区厨房厕所冲凉房水沟，砌筑抹灰，贴墙地砖，包工面议'
      },
      {
        title: '广东省东莞市-招瓦工班',
        num: 6,
        price: '面议',
        detail: '工地生活区厨房厕所冲凉房水沟，砌筑抹灰，贴墙地砖，包工面议'
      },
      {
        title: '广东省东莞市-招瓦工班',
        num: 6,
        price: '面议',
        detail: '工地生活区厨房厕所冲凉房水沟，砌筑抹灰，贴墙地砖，包工面议'
      },
    ],
    pagesize: 20,
    start: 1,
    province: '',
    city: '',
    worktype: 0,//一级工种id
    worksubtype: 0//二级工种id
  },
  // 事件处理函数

  onLoad: function (options) {
    that = this
    if (app.logininfo) {
      this.getdata();
    } else {
      util.setwatcher(app, this.afterlogin)
    }
    wx.hideTabBar()
  },
  afterlogin: {
    logininfo: res => {
      that.getdata();
    }
  },
  getdata() {
    let { carouselimg, pagesize, start, province, city, worktype, worksubtype } = that.data, recruitlist = []
    wx.showLoading({
      title: '加载中...',
    })
    api.getSwiperlist(res => {
      wx.hideLoading()
      if (res.data.issuccess == 1) {
        carouselimg = res.data.list
        that.setData({ carouselimg })
      }
    })
    api.geturgentRecruitlist({ pagesize, start, province, city, worktype, worksubtype }, res => {
      if (res.data.issuccess == 1) {
        let { total, list } = res.data
        if (list.length > 0) {
          list.forEach(x => {
            x['date'] = util.formatTime(new Date(x.updateDate * 1000))
            recruitlist.push(x)
          })
          that.setData({ recruitlist, total })
        }
      }
    })
  },
  todetail(e) {
    let { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: '../recruitmentDetail/recruitmentDetail?id=' + id,
    })
  },
  to(e) {
    let { url } = e.currentTarget.dataset
    if (url == 'jobHunting') {
      wx.switchTab({
        url: `../${url}/${url}`,
      })
    } else {
      wx.navigateTo({
        url: `../${url}/${url}`,
      })
    }
  },
})
